﻿using System.Collections;
using UnityEngine;


public class Exp : MonoBehaviour
{
    private PlayerCharacterController play;
    Vector3 vt;
    private bool isfand;
    public float expnum;
    // Use this for initialization
    void Start()
    {
        play = GameObject.FindWithTag("Player").GetComponent<PlayerCharacterController>();
        vt = transform.position + new Vector3(0, 1.5f, 0);
    }

    // Update is called once per frame
    void Update()
    {

        if (isfand)
        {
            Vector3 target = play.transform.position + new Vector3(0,1,0);
            transform.position = Vector3.MoveTowards(transform.position, target, 0.2f);
        }
        else
        {
            transform.position = Vector3.Lerp(transform.position, vt, 0.05f);
            float a = Vector3.Distance(transform.position, vt);
            if (a <= 0.001)
            {
                isfand = true; 
            }
        }
    }

    private void OnTriggerEnter(Collider other)
    {
        PlayerCharacterController player = other.GetComponent<PlayerCharacterController>();  
        if (player != null)
        {
            play.exp += expnum;
            play.ui.PlayExp(play.ex);
            Destroy(gameObject);
        }
    }
}
